//
//  main.m
//  BlockTest
//
//  Created by YaoZhaofeng on 2018/4/6.
//  Copyright © 2018年 YaoZhaofeng. All rights reserved.
//
/*
 *ARC下，通过clang转换的源码中，可以看出：
 
 *定义在全局的block是_NSConcreteGlobalBlock类型的
 *定义在局部的block是_NSConcreteStackBlock类型的
 *但是使用copy的block，并没有发现clang出来的代码中有_NSConcreteMallocBlock，只是给block发了一个copy消息，应该是运行时生成堆block
 *
 *ARC下，通过运行时打印的结果看，
 *定义在全局和局部的block都是_NSConcreteGlobalBlock的，但是如果局部block内部引用了局部变量，那么就成为了_NSConcreteMallocBlock类型
 *使用copy的block，是_NSConcreteMallocBlock类型的
 */
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

void(^globalBlock)(void) = ^{printf("i'm a global block!\n");};
void(^copyBlock)(void);

int main(int argc, const char * argv[]) {
    void(^block1)(void) = ^{ printf("i'm a stack block!\n"); };        //栈block
    
//    globalBlock = ^{
//        printf("am i a global block!\n");
//    };
     void(^block2)(void) = [^{
        printf("am i a global block!\n");
    } copy];
    
    __block int a = 100;
    void(^block3)(void) = ^{
        NSLog(@"a = %d", a);
    };
    copyBlock = [block3 copy];
    NSLog(@"block1::%@ isa::%@", block1, object_getClass(block1));
    NSLog(@"block2::%@ isa::%@", block2, object_getClass(block2));
    NSLog(@"block3::%@ isa::%@", block3, object_getClass(block3));
    NSLog(@"globalBlock::%@ isa::%@", globalBlock, object_getClass(globalBlock));
    NSLog(@"copyBlock::%@ isa::%@", copyBlock, object_getClass(copyBlock));
    
    return 0;
}
